package com.test.day03.method01;

import java.io.File;

/**
 * @program: javaTest
 * @author: luhd
 * @create: 2021-08-01
 */
public class Demo03File {
    public static void main(String[] args) {
        show01(); // 获取绝对路径
        show02(); // 获取相对路径
        show03(); // 获取文件名
        show04(); // 获取文件的大小
    }
    private static void show01(){
        File f1 = new File("D:\\myProject\\javaTest\\a.txt");
        String absolutePath1 = f1.getAbsolutePath();
        System.out.println(absolutePath1);

        File f2 = new File("a.txt");
        String absolutePath2 = f2.getAbsolutePath();
        System.out.println(absolutePath2);
    }
    private static void show02(){
        File f1 = new File("D:\\myProject\\javaTest\\a.txt");
        File f2 = new File("a.txt");
        String path1 = f1.getPath();
        String path2 = f2.getPath();
        System.out.println(path1);
        System.out.println(path2);
    }
    private static void show03(){
        File f1 = new File("D:\\myProject\\javaTest\\a.txt");
        File f2 = new File("D:\\myProject\\javaTest");
        String name1 = f1.getName();
        String name2 = f2.getName();
        System.out.println(name1);
        System.out.println(name2);
    }
    private static void show04(){
        File f1 = new File("D:\\myProject\\javaTest\\javaTest.iml");
        long l1 = f1.length();
        System.out.println(l1);
        // 文件夹没有大小的概念，只能获取文件的大小
    }
}
